public class SchedulerD implements Scheduler
{
    private String message;
    
    @Override
    public boolean schedule(TourOffering offering)
    {
        // initially just check that tour isn't over-filled
        if (offering.getNumReservations() <= offering.getTour().getMaxSize())
        {
            // check events' provider has enough room
            for (Event e : offering.getTour().getEvents())
            {
                // check if provider can hold all reservations
                // for all events except lodging, reservations are based on max size, not actual
                if (e.getProvider() != null && ((e.getEventType() == EventType.LODGING && e.getProvider().getCapacity() < offering.getNumReservations())
                        || (e.getEventType() != EventType.LODGING && e.getProvider().getCapacity() < offering.getTour().getMaxSize())))
                {
                    message = e.getProvider().getName() + " over capacity, trying other providers.";
                    return false;
                }
            }
        }
        else
        {
            message = "Tour over capacity";
            return false;
        }
        
        // offering over-filled or event provider does not have sufficient capacity
        message = "Events have sufficient capacity with initial provider.";
        return true;
    }
    
    @Override
    public String getMessage()
    {
        return "Level D: " + message;
    }
}
